package com.zhong.gang.app.ui.zhongzhuan.shou;

import androidx.annotation.NonNull;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.ActivityZhongZhuanShouBinding;
import com.zhong.gang.app.ui.zhongzhuan.ZhongZhuanBean;
import com.zhong.gang.app.ui.zhongzhuan.ZhongZhuanPersenter;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.bean.MaterialBean;
import com.zhong.gang.applib.controller.ImgController;
import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.applib.ui.adapter.AddImgAdapter;

/**
 * 中转收货
 */
public class ZhongZhuanShouAct extends ActBase<ActivityZhongZhuanShouBinding> {
    private AddImgAdapter imgAdapter;
    private ImgController imgController;
    private ZhongZhuanPersenter zhongZhuanPersenter;
    private static final String ID = "ID";
    public static final void openAct(Context context,int id){
        Intent intent = new Intent(context,ZhongZhuanShouAct.class);
        intent.putExtra(ID,id);
        context.startActivity(intent);
    }
    @Override
    public int LayoutRes() {
        return R.layout.activity_zhong_zhuan_shou;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "中转收货";
    }

    @Override
    public void initView() {
        bind.setAct(this);
        imgController = new ImgController();
        zhongZhuanPersenter = new ZhongZhuanPersenter(this);
        imgAdapter = imgController.initImgAdapter(this,bind.imgRecyclerView,100);
        getData();
    }


    @Override
    public void getData() {
        super.getData();
        zhongZhuanPersenter.getDetail(getIntent().getIntExtra(ID,0),new ActCallBack<BaseDataBean<ZhongZhuanBean>>(){
            @Override
            public void onResponse(BaseDataBean<ZhongZhuanBean> data) throws Exception {
                super.onResponse(data);
                if (data.getResult() == null)
                    return;

                if (data.getResult().getOrderSend() != null && data.getResult().getOrderSend().getOrderSendDispatchingCar() != null){
                    ZhongZhuanBean.OrderSendBean.OrderSendDispatchingCarBean bean = data.getResult().getOrderSend().getOrderSendDispatchingCar();
                    bind.startAddress.setText(":"+ bean.getStartLocal());
                    bind.endAddress.setText(":"+ bean.getEndLocal());
                    bind.carNum.setText(":"+ bean.getCarNum());
                    bind.carSn.setText(":"+ bean.getSn());
                }

                bind.sn.setText(data.getResult().getSn());
                imgController.addImgView(imgAdapter,data.getResult().getFalfPhoto());
                imgController.addImgView(imgAdapter,data.getResult().getFullPhoto());
                for (MaterialBean bean : data.getResult().getMaterialTypeDetailList()){
                    bind.material.addView(bean);
                }
                bind.sure.setVisibility(data.getResult().isDone()?View.VISIBLE:View.GONE);
            }
        });
    }

    /**
     * 点击事件
     * @param view
     */
    public void onViewClicked(View view){
        zhongZhuanPersenter.sureDone(this,getIntent().getIntExtra(ID,0),null);
    }
}
